package com.arcticcoding.telemetrie;

import java.util.List;

import com.arcticcoding.dto.ImageFrame;
import com.arcticcoding.telemetrie.comm.CameraResponse;
import com.arcticcoding.telemetrie.comm.GPSResponse;
import com.arcticcoding.telemetrie.comm.TelemetrieComm;
import com.arcticcoding.telemetrie.comm.TelemetrieResponse;
import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;

public abstract class TelemetrieClientListener extends Listener {
	
//	private static final String TAG = "com.arcticcoding.telemetrie.ClientListener";
	
	public abstract void cameraImageReceived(ImageFrame frame);
	
	public abstract void cameraSupportedFrameRatesReceived(List<Integer[]> frameRates);
		
//	public abstract void cameraSupportedResolutionsReceived(List<Camera.Size> cameraSized);
	
	public abstract void geoLocationReceived(com.arcticcoding.dto.Location location);
	
	
	@Override
	public void disconnected(Connection conn) {
//		Log.d(TAG, "Disconnected");
		super.disconnected(conn);
	}
	
	@Override
	public void received(Connection conn, Object o) {
		if(o instanceof TelemetrieComm) {
			if(o instanceof TelemetrieResponse) {
				if(o instanceof CameraResponse) {
					CameraResponse response = (CameraResponse)o;
					
					switch(response.type) {
					case IMAGE_FRAME:
						if(response.payload instanceof ImageFrame)
							cameraImageReceived((ImageFrame)response.payload);
						else
//							Log.d(TAG, "Unknown payload");
						break;
					case SUPPORTED_FRAME_RATES:
//						Log.d(TAG, "Frame rates! Not spported yet");
						break;
					case SUPPORTED_RESOLUTIONS:
//						Log.d(TAG, "Resolutions! Not supported yet");
						break;
					default:
						break;
					}
				} else if(o instanceof GPSResponse) {
					GPSResponse response = (GPSResponse)o;
					
					switch(response.type) {
					case LOCATION:
//						Log.d(TAG, "Location! Not supported yet");
						break;
					default:
						break;
					}
				}
			}
		} else {
//			Log.d(TAG, "Unknown message type: " + o.toString());
		}
		super.received(conn, o);
	}
}
